import React, { Component } from 'react';
import { routerRedux } from 'dva/router';
import { Flex, Button, Icon, Badge } from 'antd-mobile';
import storesvg from '../../assets/svg/storesvg.svg';
import guanzhu from '../../assets/svg/guanzhu.svg';
import weiguanzhu from '../../assets/svg/weiguanzhu.svg';
import goodsCart from '../../assets/svg/goodsCart.svg';

import { cartbar } from "./CartBar.less";

class CartBar extends Component {
  constructor(props) {
    super(props);
  }



  // 加入购物车处理
    addCart = () => {
        const { isFav, cartCount, spec, dispatch, goodsId, showT = false, storeId=0 } = this.props;
        if(showT==true) {this.props.dispatch({ type:'goodsDetail/addCartOrBuyEFF', obj: { saveType:0,goodsId: this.props.goodsId, specId: this.props.spec.specId } });this.props.open(false, 1)}
        else this.props.open(true, 1);
    }
  // 立即购买
  gotoBuy = () => {
      const { isFav, cartCount, spec, dispatch, goodsId, showT = false, storeId=0 } = this.props;
      if(showT==true) {this.props.dispatch({ type:'goodsDetail/addCartOrBuyEFF', obj: { saveType:1, goodsId: this.props.goodsId, specId: this.props.spec.specId } });this.props.open(false, 2)}
      else this.props.open(true,2);
  }

  render() {
     // console.log(this.props, "saasdfasdf");
    const { isFav, cartCount, spec, dispatch, goodsId, showT = false, storeId=0 ,goodsDetailInfo} = this.props;
    let { specGoodsStorage } = spec;
    
    return (
      <div className={cartbar}>
        <Flex style={{
          width: '100%',
        }}
        >

        {storeId!=0? <Flex.Item key="1" className="item" onClick={this._storecollection}>
            <Flex  direction="column" justify="around"onClick={()=>{
                storeId!=0? this.props.dispatch(routerRedux.push({
                    pathname: `/storesShow/${storeId}`,
                })):''}}
            >
                <Icon type={storesvg.id} />
                <div>店铺</div>
            </Flex>
        </Flex.Item>:""}

            <Flex.Item key="3" className="item" onClick={() =>{
                dispatch({ type:'goodsDetail/favgoodsEFF', obj:{ favType:1, goodsId, isFav: isFav==1 ? 0 : 1 } });
            }}>
                <Flex  direction="column" justify="around">
                    <Icon style={ isFav != 1 ?{width:'.36rem',height:'.36rem'}:{width:'.36rem',height:'.36rem'} }
                          type={ isFav != 1 ?  weiguanzhu.id : guanzhu.id } />
                    <div>收藏</div>
                </Flex>
            </Flex.Item>
            <Flex.Item
                key="2"
                className="item"
                // style={{ flex: 1, textAlign: 'center', height: "100%" }}
                onClick={() => {
                    this.props.dispatch(routerRedux.push({
                        pathname: '/cart',
                    }));
                }}
            >
                <Flex  direction="column" justify="around">
                    <Badge
                        text={cartCount}
                        style={{
                            position: 'absolute',
                            top: '0rem',
                            // left: '.08rem',
                        }}
                    >
                        <Icon type={ goodsCart.id } />
                    </Badge>
                    <div style={{ fontSize: '0.24rem' }}>购物车</div>
                </Flex>

            </Flex.Item>
          <Flex.Item className="addCart">
              {
                  true ?goodsDetailInfo.activityType  ==110?<Flex direction="row" justify="center" style={{ height: "100%" }}>
                          <Flex
                              justify="center"
                              direction="column"
                              style={{  backgroundColor:'#FFE3E9',width:"100%",height:"1rem" }}
                              // disabled={ specGoodsStorage == 0 || this.props.disabled }
                              onClick={ ()=>{this.props.open(true,2,0);console.log(11111)} }
                              >
                              <div style={{color:"#F93861",width:"100%",textAlign:"center",fontSize:".3rem"}}>
                                  ¥{goodsDetailInfo.storePrice}
                              </div>
                              <div style={{color:"#F93861",width:"100%",textAlign:"center",fontSize:".3rem",marginTop:".1rem"}}>
                                  单独购买
                              </div>
                          </Flex>
                          <Flex
                              justify="center"
                              direction="column"
                              style={{  backgroundColor:'#FF0036',width:"100%",height:"1rem" }}
                              // disabled={ specGoodsStorage == 0 || this.props.disabled}
                              onClick={ ()=>{this.props.open(true,2,1);} } >
                              <div style={{color:"#fff",width:"100%",textAlign:"center",fontSize:".3rem"}}>
                                  ¥{goodsDetailInfo.activityPrice}
                              </div>
                              <div style={{color:"#fff",width:"100%",textAlign:"center",fontSize:".3rem",marginTop:".1rem"}}>
                                  发起拼团
                              </div>
                          </Flex>
                      </Flex>:<Flex direction="row" justify="center" style={{ height: "100%" }}>
                          <Button
                              style={{  backgroundColor:'#FF9402' }}
                              // disabled={ specGoodsStorage == 0 || this.props.disabled }
                              onClick={ this.addCart }
                              type="primary">
                              加入购物车
                          </Button>
                          <Button
                              // disabled={ specGoodsStorage == 0 || this.props.disabled}
                              onClick={ this.gotoBuy } type="primary">立即购买</Button>
                      </Flex>
                      :<Flex>
                          <Button
                              style={{  backgroundColor:'#ccc' }}
                              type="primary">
                              已经抢光（待做、后台接口没有返回相应的字段）
                          </Button>
                      </Flex>
              }
          </Flex.Item>
        </Flex>
      </div>
    );
  }
}

export default  CartBar;
